<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('头程发货单-修改')" />
	<th:block th:include="include :: businessCSS" />
	<style>
        .main-content{position: relative;}
        .topbtns{position:fixed;top: 0;width: 100%;z-index: 9999;background-color: #fff;}
		.preservationBtn{padding: 10px;margin: 0;position: fixed;top: 0;z-index: 9999;background: #fff;width: 100%;}
		.preservationBtn input{font-size: 16px;background-color: rgb(80, 138, 238);color: #fff;border: none;padding: 5px 30px;border-radius: 5px;cursor: pointer;}
		.layui-table-tool-temp{padding-right: 30px;}
        .getDetailUpload,.getDetailUpload2{cursor: pointer;}
        .layui-table-tool-self{display: none;}
	</style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
<!--        <div class="topbtns"><th:block th:include="include :: business_btn" /></div>-->
	    <div class="north" style="background-color: #fff;margin-top: 55px;">
			 <div class="layui-form-item preservationBtn">
                <button class="layui-btn layui-btn-normal dhicon btn-edit" type="button" lay-submit lay-filter="btn-edit" id="btn-edit">保存</button>
<!--                <button class="layui-btn layui-btn-normal dhicon btn-edit" type="button" lay-submit lay-filter="btn-edit" id="btn-order">头程下单</button>-->
<!--                <button class="layui-btn layui-btn-normal dhicon btn-edit" type="button" lay-submit lay-filter="btn-edit" id="btn-cancel">取消头程</button>-->
<!--                <button class="layui-btn layui-btn-normal dhicon btn-sh" type="button" lay-submit lay-filter="btn-sh" id="btn-sh">审核</button>-->
<!--                <button class="layui-btn layui-btn-normal dhicon btn-retreat" type="button" lay-submit lay-filter="btn-retreat" id="btn-retreat">回退</button>-->
			</div>
<!--			<div style="width: 100%;height: 65px;background: #f6f6f6;"></div>-->
			<div class="forminput"></div>
    	</div>
        <div style="width: 100%;height: 10px;background: #f6f6f6;"></div>
        <div>
            <table class="layui-hide" id="mjdhtable" lay-filter="mjtable"></table>
            <script type="text/html" id="zjtoolbar">
                <div style="padding: 16px;display: flex;justify-content: space-between;">
                    <div  style="font-weight: 700;font-size: 18px;">海外头程装箱清单</div>
            		<div>
<!--                        <button class="layui-btn layui-btn-normal dhicon" th:classappend="${enableEdit} == 1 ?'':'layui-btn-disabled'" type="button" th:disabled="${enableEdit} == 1 ?false:true" lay-event="addbtn" id="btn-sh">新增</button>-->
<!--                        <button class="layui-btn layui-btn-danger dhicon" th:classappend="${enableEdit} == 1 ?'':'layui-btn-disabled'" type="button" th:disabled="${enableEdit} == 1 ?false:true" lay-event="mjbtn_save" id="btn-sh">删除</button>-->
            		</div>
            	</div>
            </script>
        </div>
        <th:block th:include="include :: pageFooter" />
    </form>
	</div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: inlineJS" />


<script th:inline="javascript">
	/*<![CDATA[*/
	var fields = [[${fields}]];
    var fieldsList = [[${fieldsList}]];
	var fieldsHiddenList = [[${fieldsHiddenList}]];
	var moduleTable = [[${moduleTable}]];
	var enableEdit = [[${enableEdit}]];
    // 头程装箱清单数据
    var List=[[${List}]];
    //表头数据
    var headData=[[${headData}]];

    var tablecols=[[ //标题栏
        {align: 'center', title: '商品信息', colspan: 6,width: 100}
        ,{align: 'center', title: '装箱情况', colspan: 17,width: 100}
        // ,{align: 'center', title: '操作',width:150,fixed: 'right',rowspan: 2,toolbar: "#barDh",type: "normal"}
    ], [
        {align: 'center',field: 'serial', title: '操作', width: 100}
        ,{field: 'commodityCode', title: '商品编码', width: 100}
        ,{field: 'nameGoodsCn', title: '商品名称', width: 100}
        ,{field: 'asin', title: 'SKU', width: 100}
        ,{field: 'sku', title: 'ASIN', width: 100}
        ,{field: 'fnsku', title: 'FNSKU', width: 100}
        ,{field: 'nameGoodsCn', title: '商品品名(中文)', width: 100}
        ,{field: 'nameGoodsEn', title: '商品品名(英文)', width: 100}
        ,{field: 'codeGoodsHs', title: '海关编码', width: 100}
        ,{field: 'nameMaterialCn', title: '商品材质(中文)', width: 100}
        ,{field: 'nameMaterialEn', title: '商品材质(英文)', width: 100}
        ,{field: 'numPlanDeliver', title: '计划发货数量', width: 100}
        ,{field: 'theFirstCase', title: '第一箱', width: 100,edit:'text'}
        ,{field: 'theSecondCase', title: '第二箱', width: 100,edit:'text'}
        ,{field: 'theThirdCase', title: '第三箱', width: 100,edit:'text'}
        ,{field: 'theFourCase', title: '第四箱', width: 100,edit:'text'}
        ,{field: 'theFiveCase', title: '第五箱', width: 100,edit:'text'}
        ,{field: 'theFixCase', title: '第六箱', width: 100,edit:'text'}
        ,{field: 'theSevenCase', title: '第七箱', width: 100,edit:'text'}
        ,{field: 'theEightCase', title: '第八箱', width: 100,edit:'text'}
        ,{field: 'theNineCase', title: '第九箱', width: 100,edit:'text'}
        ,{field: 'theTenCase', title: '第十箱', width: 100,edit:'text'}
    ]]

	//移除表格编辑属性  不等于制单中的时候禁用
	if (headData['state'] != 0){
		$.each(tablecols[1],function(i,v){
					delete v['edit']
				}
		)
	}


	var $,layer,form,table,nid,noTable;
    layui.use(['laydate','form','layer','jquery','util','element','upload','table'], function () {
        $ = layui.$,layer = layui.layer,form = layui.form,laydate = layui.laydate,util = layui.util,element=layui.element,upload = layui.upload,table = layui.table;
        beforeInit();//表单初始化之前的动作集合
		//初始化操作
		headcom3()
        nid=$('#nid').val()
         // 保存按钮事件变化
        $(function(){
           $('.tp-save').attr('onclick','')
           $('.tp-save').attr('lay-filter','btn-edit')
           $('.tp-save').attr('lay-submit',true)
        })

        
        // 保存操作
        form.on('submit(btn-edit)', function(data){
            var is_return = false//是否中断保存
            fieldsList.map((v,i)=>{
                if(v.fieldFrontRequired){
                    if(!$('#'+v.fields).val()){
                         layer.msg(v.fieldName+'不能为空')
                         is_return=true
                    }
                }
            })
            if(is_return) return;
            $.modal.loading("正在处理中，请稍后...");
            listData1.map((v,i)=>{
                v.iid=i+1
            })
		    $.post("/logstics/fbaDispatch/editpost",{infoMap:JSON.stringify(data.field),infoItems:JSON.stringify(listData1),sonData:JSON.stringify(listData1)},function(res){
                $.modal.closeLoading()
			 	layer.msg(res.msg);
                if(res.code == 0){
                   window.location.href = '/logstics/fbaDispatch/edit?guid=' + res.data;
                }
	        });
        });

        // 审核操作
        form.on('submit(btn-sh)', function(data){
			if(!data.field.state || data.field.state!='0'){
                layer.msg('订单不是制单环节,不允许审核!')
            }else{
                layer.confirm('是否确定审核', {btn : ['确定', '取消']}, function() {
                    // $.modal.loading("正在处理中，请稍后...");
                    $.post("/logstics/fbaDispatch/flowgopost",{nid:nid,guid:data.field.guid,state:1},function(res){
                        if(res.code==0){
							layer.msg("审核成功");
							setTimeout(function(){
								window.location.reload();
							}, 1000);
						}
	                });
                });
            }
        });
		// 回退操作
		form.on('submit(btn-retreat)', function(data){
			if(!data.field.state || data.field.state!='1'){
				layer.msg('订单不是审核环节,不允许回退!')
			}else{
				layer.confirm('是否确定回退', {btn : ['确定', '取消']}, function() {
					// $.modal.loading("正在处理中，请稍后...");
					$.post("/logstics/fbaDispatch/flowbackpost",{nid:nid,guid:data.field.guid,state:0},function(res){
						if(res.code==0){
							layer.msg("回退成功");
							setTimeout(function(){
								window.location.reload();
							}, 1000);
						}
					});
				});
			}
		});


        var listData1=List ?List:[]

		// 初始化表格
        $.tablelist.init({
            elem: '#mjdhtable'
            ,data: listData1
            , page: false
            , even: true
            , limit: 10000
            , totalRow: false
            , cols: tablecols
            , toolbar: '#zjtoolbar'
            , defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
            , height: '550'
            , done: function (res, curr, count) {
                listData1 = table.cache.mjdhtable;//每次重载都赋值更新表缓存
				if (headData['state'] == 1){
					$('.btn-sh').attr('disabled',true)
					$('.btn-sh').css('background',"#bbb")
					$('.btn-edit').attr('disabled',true)
					$('.btn-edit').css('background',"#bbb")
					$('.layui-col-xs4').attr("disabled",true);
					$('input').attr('disabled','disabled')
					$('input').addClass('canntEdit')
					$('.forminput').addClass('layui-disabled')
				}

            },success:function(a,b,c){
            }
        });

        //监听单元格编辑
        table.on('edit(mjtable)', function(obj){
            // calculation()
         });


        //监听单元格编辑
        // table.on('edit(zjtable)', function(obj){
        //
        //  });

    });


</script>

</body>
</html>